package web.servlet.appFunction;

import domain.AppFunction;
import domain.LyyBaseServlet;
import domain.response.GetAllFunctionResponse;
import service.AppFunctionService;
import service.impl.AppFunctionServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/getAllFunction")
public class GetAllFunctionServlet extends LyyBaseServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        super.doPost(request,response);
        AppFunctionService service=new AppFunctionServiceImpl();
        List<AppFunction> all=null;
        Exception exception=null;
        try {
            all = service.getAll();
        } catch (Exception e) {
            e.printStackTrace();
            exception=e;
        }
        GetAllFunctionResponse getAllFunctionResponse=new GetAllFunctionResponse();
        if ((exception!=null)){
            getAllFunctionResponse.setStatus(0);
            getAllFunctionResponse.setErrMsg(exception.getMessage());
        }else {
            getAllFunctionResponse.setFunctionList(all);
        }
        jsonResponse(response,getAllFunctionResponse);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
